package com.dtdream.manager.controller;

import java.util.List;
import java.util.Map;

import entity.PageResult;
import entity.Result;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.dubbo.config.annotation.Reference;
import com.dtdream.pojo.TbBrand;
import com.dtdream.sellergoods.service.BrandService;

@RestController
@RequestMapping("/brand")
public class BrandController {

	@Reference
	private BrandService brandService;

	//返回品牌全部列表
	@RequestMapping("/findAll")
	public List<TbBrand> findAll(){
		return brandService.findAll();
	}
	//返回品牌分页列表
	@RequestMapping("/findPage")
	public PageResult findPage(int page,int rows){
		return brandService.findPage(page,rows);
	}
	//添加品牌
	@RequestMapping("/add")
	public Result add(@RequestBody TbBrand tbBrand){
		try {
			brandService.add(tbBrand);
			return new Result(true,"添加成功");
		}catch (Exception e){
			e.printStackTrace();
			return new Result(false,"添加失败");
		}
	}
	//更新品牌
	@RequestMapping("/update")
	public Result update(@RequestBody TbBrand tbBrand){
		try{
			brandService.updata(tbBrand);
			return new Result(true,"修改成功");
		}catch(Exception e){
			e.printStackTrace();
			return new Result(false,"修改失败");
		}
	}
	//获取品牌
	@RequestMapping("/findOne")
	public TbBrand findOne(@RequestParam Long id){
		TbBrand tbBrand = brandService.findOne(id);
		return tbBrand;
	}

	//批量删除
	@RequestMapping("/delete")
	public Result delete(@RequestParam Long[] ids){
		try {
			brandService.delect(ids);
			return new Result(true,"删除成功");
		}catch (Exception e){
			return new Result(false,"删除失败");
		}
	}

	/**
	 * 查询+分页
	 * @param brand
	 * @param page
	 * @param rows
	 * @return
	 */
	@RequestMapping("/search")
	public PageResult search(@RequestBody TbBrand brand,int page,int rows){
		return brandService.findPage(brand, page, rows);
	}

	/**
	 * 品牌下拉框数据
	 */
	@RequestMapping("/selectOptionList")
	public List<Map> selectOptionList(){
		return brandService.selectOptionList();
	}
}